# from fastapi import APIRouter, Depends
# import db.version_config_2_crud as dbutils
# import utils
# from db.database import SessionLocal, get_db
# from sqlalchemy.orm import Session
# from domain.response import success, error
# from domain.domain import UpdateVO
# from db.schemas import VersionCreate
# import datetime
#
# router = APIRouter(
#     prefix="/VersionConfig",
#     tags=["VersionConfig"],
#     dependencies=[],
#     responses={404: {"description": "VersionConfig error"}}
# )
#
#
# @router.get("/open")
# async def open_version(bid: str, msg: str, db: Session = Depends(get_db)):
#
#     version = await dbutils.open_version(bid, msg, db)
#     if version is None:
#         return await error(code=41001, msg='This version has been deleted!')
#     return await success(version)
#
#
# @router.get("/close")
# async def close_version(bid: str, msg: str, db: Session = Depends(get_db)):
#     version = await dbutils.close_version(bid, msg, db)
#     if version is None:
#         return await error(code=41001, msg='This version has been deleted!')
#     return await success(version)
#
#
# @router.post("/delete")
# async def delete_version(bid: str, msg: str, db: Session = Depends(get_db)):
#     version = await dbutils.delete_version(bid, msg, db)
#     if version is None:
#         return await error(code=41001, msg='This version has been deleted!')
#     return await success(version)
#
#
# @router.post("/add")
# async def add_version(ver: VersionCreate,
#                       msg: str,
#                       db: Session = Depends(get_db)):
#     str_attrs = ['version', 'md5', 'download_url', 'cpu_arch', 'channel']
#     int_attrs = ['max_os_api', 'min_os_api', 'max_version', 'min_version']
#     for i in range(len(str_attrs)):
#         if ver[str_attrs[i]] == '':
#             return await error(code=41002 + i, msg="The %s can't be empty!" % str_attrs[i])
#
#     for i in range(len(int_attrs)):
#         if ver[int_attrs[i]] is None:
#             return await error(code=41007 + i, msg="The %s can't be empty!" % int_attrs[i])
#
#     version = await dbutils.add_version(ver, msg, db)
#     return await success(version)
#
#
# @router.post("/update")
# async def update_version(ver: VersionCreate,
#                          msg: str,
#                          db: Session = Depends(get_db)):
#     str_attrs = ['version', 'md5', 'download_url', 'cpu_arch', 'channel']
#     int_attrs = ['max_os_api', 'min_os_api', 'max_version', 'min_version']
#     for i in range(len(str_attrs)):
#         if ver[str_attrs[i]] == '':
#             return await error(code=41002 + i, msg="The %s can't be empty!" % str_attrs[i])
#
#     for i in range(len(int_attrs)):
#         if ver[int_attrs[i]] is None:
#             return await error(code=41007 + i, msg="The %s can't be empty!" % int_attrs[i])
#
#     version = await dbutils.update_version(ver, msg, db)
#     if isinstance(version, dict):
#         return await version
#     return await success(version)
